package com.sduept.nwld.lbtz.math;

public class ComplexNumber {
	
	private static final Integer MP = 0;  //幅值相角
	private static final Integer RI = 1;  //实部虚部
	
	public ComplexNumber() {}
	public ComplexNumber(Double magnitude,Double phase) {
		this.value1 = magnitude;
		this.value2 = phase;
		this.type = MP;
	}
	
	/**
	 * 幅值
	 */
	private Double value1;
	/**
	 * 相位
	 */
	private Double value2;
	
	/**
	 * 类型为0：幅值相角   类型为1：实部虚部
	 */
	private Integer type = MP;
	
	public void setMagnitudeAndPhase(Double magnitude,Double phase) {
		this.value1 = magnitude;
		this.value2 = phase;
		this.type = MP;
	}
	public void setRealAndImaginary(Double realPart,Double imaginaryPart) {
		this.value1 = realPart;
		this.value2 = imaginaryPart;
		this.type = RI;
	}
	public Double getMagnitude() {
		Double m = null;
		if(type == MP) {
			m = value1;
		}else if(type == RI){
			m = ComplexNumberUtil.convertToMP(value1, value2)[0];
		}
		return m;
	}
	public Double getPhase() {
		Double m = null;
		if(type == MP) {
			m = value2;
		}else if(type == RI){
			m = ComplexNumberUtil.convertToMP(value1, value2)[1];
		}
		return m;
	}
	public Double getRealPart() {
		Double m = null;
		if(type == RI) {
			m = value1;
		}else if(type == MP){
			m = ComplexNumberUtil.convertToRI(value1, value2)[0];
		}
		return m;
	}
	public Double getImaginaryPart() {
		Double m = null;
		if(type == RI) {
			m = value2;
		}else if(type == MP){
			m = ComplexNumberUtil.convertToRI(value1, value2)[1];
		}
		return m;
	}
}